package com.vpen.account.demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vpen.account.demo.entity.AccountRole;
import com.vpen.account.demo.entity.AccountUserRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户确实表，一个用户多个角色，一对多(AccountUserRole)表数据库访问层
 *
 * @author vpen
 * @since 2022-08-16 09:48:59
 */
public interface AccountUserRoleDao extends BaseMapper<AccountUserRole> {

    /**
     * 获取用户的角色
     *
     * @param userId 用户id
     * @return java.util.List<com.vpen.account.demo.entity.AccountRole>
     * @author 韦鹏
     * @date 2022/8/16 10:05
     **/
    @Select("SELECT id,`name` FROM account_user_role aur LEFT JOIN account_role ar on aur.role_id=ar.id WHERE user_id=#{userId}")
    List<AccountRole> getUserRolesByUserId(@Param("userId") Long userId);

}

